package com.quyou.funtour.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quyou.funtour.dao.UserDao;
import com.quyou.funtour.po.UserPo;
import com.quyou.funtour.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao, UserPo> implements UserService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * 小程序端用户登录
     * @param user
     * @param msg
     * @return
     */
    @Override
    public UserPo login(UserPo user, String msg) {
        UserPo loginUser = getOne(new QueryWrapper<UserPo>().eq("open_id", user.getOpenId()));
        if(loginUser==null){
            save(user);
        }
        //session.setAttribute("login_user",loginUser);
        redisTemplate.opsForValue().set(msg,user);
        return loginUser;
    }
}
